package com.mew.common.rest.login;

import com.mew.common.entity.user.Profile;
import com.mew.common.entity.user.User;
import com.mew.common.rest.MewResponse;
import com.mew.common.rest.bo.MewSession;
import io.netty.buffer.ByteBuf;
import lombok.*;


/**
 * @Date 2020/11/14 0014
 **/
@Data
@ToString
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class LoginResponseMessage extends MewResponse<LoginResponseMessage> {
    private long uid; //userId  ****** 重要信息
    private long tk;  //token   ****  重要信息

    private int headPath;//头像
    private long goldNumber; // 金币
    private long jewelNumber; // 砖石数量
    private int userLevel; // 等级
    private int vipLevel; // VIP等级
    private int guideType; //是否新手引导 0未指引,  1 已指引

//    private byte admin;//白名单管理员可打圈
//    private byte bulletin;//弹公告

//------- 不发前端
    private int clear;

    @Override
    public void write(ByteBuf b) {

        writeLong(b, this.uid);
        writeInt(b, this.headPath);
        writeLong(b, this.goldNumber);
        writeLong(b, this.jewelNumber);
        writeInt(b, this.userLevel);
        writeInt(b, this.vipLevel);
        writeInt(b, this.guideType);
//        writeByte(b, this.bulletin);

    }

    @Override
    public LoginResponseMessage read(ByteBuf b) {
        this.uid = readLong(b);
        this.headPath = readInt(b);
        this.goldNumber = readLong(b);
        this.jewelNumber = readInt(b);
        this.userLevel = readInt(b);
        this.vipLevel = readInt(b);
        this.guideType = readInt(b);
        return this;
    }

    public LoginResponseMessage buildData(User user, Profile profile, MewSession session){
        this.uid = user.getId();
        this.tk = session.tk;

        this.headPath = user.getHeadPath();
        this.goldNumber = profile.getGoldNumber();
        this.jewelNumber = profile.getJewelNumber();
        this.userLevel = profile.getUserLevel();
        this.vipLevel = profile.getVipLevel();
        this.guideType = user.getGuideType();
        return this;
    }


    public String toSimpleString(){
        StringBuilder buf = new StringBuilder(64);
        buf.append("LoginResponseMessage=");
        buf.append(" uid: ").append(this.getUid())
                .append("guideType: ").append(this.getGuideType())
                .append(" goldNumber: ").append(this.getGoldNumber())
                .append(" jewelNumber: ").append(this.jewelNumber)
                .append(" userLevel: ").append(this.userLevel)
                .append(" vipLevel: ").append(this.vipLevel);
        return buf.toString();
    }
}
